function HandlePageIeDaily(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options;
  
  this._createElements();
};
HandlePageIeDaily.prototype._createElements = function() {
  var _self = this;
  this._popupBox = new PopupBox();
  this._search = DlmanageUtils.search();
  
  tr = this._gui.mains.insertRow(-1);
  td = tr.insertCell(-1);
  td.style.backgroundColor = '#fff';
  td.colSpan = 7;
  td.appendChild(DOMUtils.getLoadingImage());
  
  this._loadData();
};

HandlePageIeDaily.prototype._loadData = function() {
  this._results = null;
  this._payments = null;
  this._parameters = null;
  this._dateZones = null;
  this._retrieveResults(1);
  this._retrievePayments(1);
  this._retrieveDateZones();
};

HandlePageIeDaily.prototype._verifyData = function() {
  if (this._results && this._dateZones && this._payments) {
    this._updateElements();
  }
};

HandlePageIeDaily.prototype._retrieveResults = function(page, order, queue, condition, from, to) {
  var _self = this;
  var args = ((condition) ?  '&c=' + condition : '1 = 1') + '&p=' + page + ((order) ? '&o=' + order : '') + ((queue) ? '&q=' + queue : '') + ((from) ?  '&from=' + from : '') + ((to) ?  '&to=' + to : '');
  new RequestUtils()._custom('ieincomedaily', args, function(result, params) { _self._results = result;
                                                                               _self._verifyData.call(_self);
                                                                             }, null);
};

HandlePageIeDaily.prototype._retrievePayments = function(page, order, queue, condition, from, to, size) {
  var _self = this;
  var args = ((condition) ?  '&c=' + condition + ' AND d.cancelled=0' : '&c=d.cancelled=0') + '&p=' + page + ((order) ? '&o=' + order : '') + '&q=' + ((queue) ? '&q=' + queue : '') + ((from) ?  '&from=' + from : '') + ((to) ?  '&to=' + to : '') + '&s=' + ((size) ? size : DlmanageUtils.number);
  new RequestUtils()._custom('payments', args, function(result, params) { _self._payments = result.data;
                                                                          _self._parameters = result;
                                                                          _self._verifyData.call(_self);
                                                                        }, null);
};

HandlePageIeDaily.prototype._retrieveDateZones = function(page, condition, date, from, to, pos) {
  var _self = this;
   var arg ="&c=d.page=\'" + this._options.template + "\' ";
  /*new RequestUtils()._read('datezone', null, 'd.page=\'' + this._options.template + '\'', null, null, null, null, function(result, params) { _self._dateZones = result.data;
                                                                                                                                            _self._verifyData.call(_self);
                                                                                                                                          }, null);*/
   new RequestUtils()._mysql('datezone', arg, function(result, params) { _self._dateZones = result.data;
                                                                          _self._parameters = result;
                                                                          _self._verifyData.call(_self);
                                                                        }, {php:'customphp/mysqlread.php',pos: (pos) ? pos : null });                                                                                                                                          
};

HandlePageIeDaily.prototype._updateElements = function() {
  var _self = this;
  DlmanageUtils.clear(this._gui.summarize);
  DOMUtils.removeTableRows(this._gui.mains, 1);
  DlmanageUtils.clear(this._gui.dateZone);
  DOMUtils.removeChildElements(this._gui.pagination);

  this._gui.summarize.receipt.appendChild(document.createTextNode('$' + (this._results.top.receipt).toFixed(2)));
  this._gui.summarize.cash.appendChild(document.createTextNode('$' + (this._results.top.cash).toFixed(2)));
  this._gui.summarize.nonCash.appendChild(document.createTextNode('$' + (this._results.top.noncash).toFixed(2)));
  
  /*--SORT--*/
  this._gui.cdate.onclick = function() { _self._retrievePayments.call(_self, _self._parameters.page, 'd.createdDate', 'ASC', _self._parameters.condition);
                                       };
  this._gui.pdate.onclick = function() { _self._retrievePayments.call(_self, _self._parameters.page, 'd.date', 'ASC', _self._parameters.condition);
                                       };
  this._gui.payer.onclick = function() { _self._retrievePayments.call(_self, _self._parameters.page, 'd.customerId', 'ASC', _self._parameters.condition);
                                       };
  this._gui.item.onclick = function() { _self._retrievePayments.call(_self, _self._parameters.page, 'd.stage', 'ASC', _self._parameters.condition);
                                      };
  this._gui.sort.onclick = function() { _self._retrievePayments.call(_self, _self._parameters.page, 'd.orderFlag', 'ASC', _self._parameters.condition)};
  
  /*--main table--*/
  if (this._payments.length == 0) {
    tr = this._gui.mains.insertRow(-1);
    td = tr.insertCell(-1);
    td.colSpan = 7;
    td.style.height = '24px';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode('N/A'));
  }
  for (k = 0, kl = this._payments.length; k < kl; k++) {
    var payment = this._payments[k];
    if (payment.cancelled) {
      continue;
    }
    tr = this._gui.mains.insertRow(-1);
    td = tr.insertCell(-1);
    td.style.height = '24px';
    td.appendChild(document.createTextNode(SimpleDate.format(payment.createdDate)));
    td = tr.insertCell(-1);
    td.appendChild(document.createTextNode(SimpleDate.format(payment.date)));
    td = tr.insertCell(-1);
    td.appendChild(document.createTextNode(DlmanageUtils.customerId(payment.customerId)));
    td = tr.insertCell(-1);
    td.appendChild(document.createTextNode(payment.stage));
    td = tr.insertCell(-1);
    td.style.textAlign = 'left';
    td.style.padding = '0 0 0 15px';
    td.appendChild(document.createTextNode(payment.orderFlag));
    td = tr.insertCell(-1);
    td.appendChild(document.createTextNode((payment.method == 'cash') ? '$' + payment.amount : ''));
    td = tr.insertCell(-1);
    td.appendChild(document.createTextNode((payment.method == 'cash') ? '' : '$' + payment.amount));
  }
  /*--DATE ZONE----*/
  this._dateZone = { created: '',
                     to: ''
                   };
  this._gui.dateZone.dateCreated.value = (this._dateZone.created) ? SimpleDate.format(this._dateZone.created) : '';
  this._gui.dateZone.dateCreated.onclick = function() { var context = this;
                                                        _self._changeDate.call(_self, this, _self._dateZone.created, function(sd) { _self._dateZone.created = sd; context.focus(); }, false);
                                                        return false;
                                                      };
  this._gui.dateZone.dateTo.value = (this._dateZone.to) ? SimpleDate.format(this._dateZone.to) : '';
  this._gui.dateZone.dateTo.onclick = function() { var context = this;
                                                   _self._changeDate.call(_self, this, _self._dateZone.to, function(sd) { _self._dateZone.to = sd; context.focus(); }, false);
                                                   return false;
                                                 };
  this._gui.dateZone.create.onclick = function() { if (_self._dateZone.created &&_self._dateZone.to) {
                                                     var date = DateZone.instance();
                                                     date.start = _self._dateZone.created;
                                                     date.end = _self._dateZone.to;
                                                     date.page = _self._options.template;
                                                     new RequestUtils()._mwrite('datezone', [date], [], function(date, params) { _self._retrieveDateZones.call(_self);}, DOMUtils.findPos(this));
                                                   } else {
                                                     window.alert('DATE NOT BE EMPTY');
                                                   }
                                                 };
  var table = document.createElement('table');
  table.style.width = '166px';
  table.cellPadding = 0;
  table.cellSpacing = 0;
  this._gui.dateZone.result.appendChild(table);
  for (var i = 0, il = this._dateZones.length; i < il; i++) {
    var date = this._dateZones[i];
    tr = table.insertRow(-1);
    tr.className = (tr.rowIndex % 2 == 0) ? 'rowodd' : 'roweven';
    td = tr.insertCell(-1);
    td.style.width = '146px';
    td.style.height = '20px';
    td.style.textAlign = 'center';
    var a = document.createElement('a');
    a.href = '#';
    a._date = date;
    a.appendChild(document.createTextNode(SimpleDate.format(date.start) + ' - ' + SimpleDate.format(date.end)));
    a.onclick = function() { _self._search.dateFrom = this._date.start;
                             _self._search.dateTo = this._date.end;
                             _self._retrieveResults.call(_self, 1, null, null, '1=1', JSON.stringify(this._date.start), JSON.stringify(this._date.end)); 
                             _self._retrievePayments.call(_self, 1, null, null, '1=1', JSON.stringify(this._date.start), JSON.stringify(this._date.end)); 
                             return false;
                           };
    td.appendChild(a);
    td = tr.insertCell(-1);
    td.style.width = '20px';
    td.style.textAlign = 'center';
    var span = document.createElement('span');
    span.appendChild(document.createTextNode('(x)'));
    span.style.cursor = 'pointer';
    span._date = date;
    span.onclick = function() { new RequestUtils()._write('datezone', [], [this._date], function(date, params) { _self._retrieveDateZones.call(_self);}, null);
                              };
    td.appendChild(span);
  }
  /*--PAGINATION--*/
  Pagination.makePagedResults(this._gui.pagination, this._parameters.page, this._parameters.total, this._parameters.size, function(page, condition) { _self._retrievePayments.call(_self, page, null, null, _self._parameters.condition); }, this, document);
  /*--SEARCH--*/
  this._paymentSearch(this._gui, function(order, queue, condition, from, to) { _self._retrieveResults.call(_self, 1, order, queue, condition, from, to); _self._retrievePayments.call(_self, 1, order, queue, condition, from, to);});
};

HandlePageIeDaily.prototype._paymentSearch = function(gui, callbackFunc) {
  var _self = this;
  this._callbackFunc = callbackFunc;

  gui.search.dateCreated.value = (this._search.dateFrom) ? SimpleDate.format(this._search.dateFrom) : '';
  gui.search.dateCreated.onclick = function() { var context = this;
                                                _self._changeDate.call(_self, this, _self._search.dateFrom, function(sd) { _self._search.dateFrom = sd; context.focus(); }, false);
                                                return false;
                                              };
  gui.search.dateCreated.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                    if (code == 13) {
                                                      _self._callbackFunc.call(_self, null, null, '1=1', (_self._search.dateFrom) ? JSON.stringify(_self._search.dateFrom) : null, (_self._search.dateTo) ? JSON.stringify(_self._search.dateTo) : null); 
                                                    }
                                                  };
  gui.search.dateTo.value = (this._search.dateTo) ? SimpleDate.format(this._search.dateTo) : '';
  gui.search.dateTo.onclick = function() { var context = this;
                                           _self._changeDate.call(_self, this, _self._search.dateTo, function(sd) { _self._search.dateTo = sd; context.focus(); }, false);
                                           return false;
                                         };
  gui.search.dateTo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                               if (code == 13) {
                                                 _self._callbackFunc.call(_self, null, null, '1=1', (_self._search.dateFrom) ? JSON.stringify(_self._search.dateFrom) : null, (_self._search.dateTo) ? JSON.stringify(_self._search.dateTo) : null); 
                                               }
                                             };
 gui.search.search.onclick = function() { _self._callbackFunc.call(_self, null, null, '1=1', (_self._search.dateFrom) ? JSON.stringify(_self._search.dateFrom) : null, (_self._search.dateTo) ? JSON.stringify(_self._search.dateTo) : null); };
};

HandlePageIeDaily.prototype._changeDate = function(label, currentDate, onChangeFunc, showTime) {
  var _self = this;
  this._wContainer = document.createElement('div');
  this._wContainer.style.left = DOMUtils.findPos(label)[0] + 'px';
  this._wContainer.style.top = DOMUtils.findPos(label)[1] + 'px';
  this._popupBox._open(this._wContainer, { pos: DOMUtils.findPos(label) });
  
  var ds = new DateSelect(currentDate, null, { container: this._wContainer, showTime: showTime });
  ds._selectFunc = function(sd) { _self._selectDate.call(_self, sd, label, onChangeFunc, showTime); };
};

HandlePageIeDaily.prototype._selectDate = function(sd, label, onChangeFunc, showTime) {
  
  onChangeFunc(sd);
  this._showDate(sd, label, showTime);
  this._popupBox._close();
};

HandlePageIeDaily.prototype._showDate = function(sd, label, showTime) {
  if (sd) { 
    label.value = SimpleDate.format(sd, showTime);
  } else {
    label.value = '';
  }
};